<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: 刘世琪
 * @Date: 2021-01-30 17:14:36
 * @LastEditors: Seven
 * @LastEditTime: 2021-02-06 02:51:12
-->
<template>
    <div>
        <div v-if="right == 0">
            <h1>首页</h1>
            <p>用户:{{username}}  等级:{{role}} UID:{{uid}}</p>
            <table border="1">
                <tr>
                    <td>名字</td>
                    <td>操作</td>
                </tr>
                    <tr v-for="coach in coach_list" :key="coach.id">
                        <td>{{coach.name}}</td>
                        <td @click="btg(coach.id)"><button >抢课</button></td>
                    </tr>
            </table>
         </div>

        <div v-else>
            <h1>本店详情</h1>
            <p>用户:{{username}}  等级:{{role}} UID:{{uid}}</p>
            <table border="1">
                <tr>
                    <td>收益</td>
                    <td>操作</td>
                </tr>
                    <tr>
                        <td>{{total_money}}元</td>
                        <td><button @click="excellence">最优秀教练</button>  <button @click="money">最有钱学员</button></td>
                    </tr>
            </table>
        
        <div>
        <br>
        <table border="1">
            <tr>
                <!-- <td>ID</td> -->
                <td>最优秀教练</td>
                <td>最有钱学员</td>
            </tr>
             <tr>
                <!-- <td>{{coach.num}}</td>  -->
                <td>{{co.coach__name}}</td>
                <td>{{coachs.user__username}}</td>
            </tr>
        </table> 
        </div>
        </div> 
    </div>
    
</template>


<script>
import axios from 'axios'
export default {
    data() {
        return {
            coach_list:{},
            total_money:{},
            co:{},
            coachs:{},
            base_url:'http://127.0.0.1:8000/',
            username: localStorage.username,
            right:localStorage.right,
            uid:localStorage.uid,
            role:localStorage.role,
            s:1,
            a:2,
        }
    },
    mounted:function(){
        this.get_coach()
        this.get_account()
    },
    methods: {
        get_coach(){
            console.log(this.role)
            axios({
                url: this.base_url + 'coach/',
                params:{
                    level:this.role
                }
            }).then(res=>{
                console.log(res.data)
                this.coach_list = res.data.data
            })
        },
        btg(coach_id){
            axios({
                url: this.base_url + 'coach_take/',
                method:'post',
                data:{coach_id:coach_id,
                        user_id:this.uid,
                    }
            }).then(res=>{
                console.log(coach_id,this.uid)
                // this.$router.push({'name':'ShowCoach',query:{id:coach_id}}) 
                this.$router.push({path:"/show_coach",query:{id:coach_id}}) 
                alert(res.data.msg)
            })
             
        },
        // 总金额
        get_account(){
            console.log(this.right)
            axios({
                url: this.base_url + 'user_account/',
            }).then(res=>{
                console.log(res.data)
                this.total_money = res.data
                
            })
        },
        // 最优秀教练
        excellence(){
            // console.log(this.right)
            axios({
                url: this.base_url + 'combine/',
                // url: this.base_url + 'good_coach/',   
                params:{
                    state:this.s
                }
            }).then(res=>{
                console.log(res.data)
                this.co = res.data
            })
        },
        money(){
            console.log(this.a)
            axios({
                url: this.base_url + 'combine/',
                // url: this.base_url + 'good_coach/',   
                params:{
                    state:this.a
                }
            }).then(res=>{
                console.log(res.data)
                this.coachs = res.data
            })
        }
    },
    created() {
        
    }
}
</script>

<style>
table{
    width: 300px;
    height: 50px; 
    border: solid burlywood;
    margin: 0 auto;
    border-collapse:collapse
}
td{
    border: green solid;
    border-collapse:collapse
}

</style>